package juc;

public class DanList
{
    Node first = null;
    //创建一个node环
    public void createNodes(int n)
    {
        if (n < 2)
        {
            System.out.println("创建失败！数量不对");
            return;
        }
        //定义一个指针
        Node temp = null;
        //从序号1开始创建环形遍历值
        for (int i = 1; i <= n; i++)
        {
            Node node = new Node(i);

            if (node.getNo() == 1)
            {
                first = node;
                first.setNext(first);//自己与自己形成环链表
                temp = first;
            }
            else
            {
                temp.setNext(node);
                node.setNext(first);
                temp = node;
            }

        }
    }

    /**
     * 展示环形链表
     */
    public void showNodes()
    {
        if (first == null)
        {
            System.out.println("没有值");
            return;
        }

        Node temp = first;
        while (true)
        {
            System.out.println(temp.getNo());
            if (temp.getNext() == first)
            {
                break;
            }
            temp = temp.getNext();
        }
    }
}
